const Koa = require("koa2");
const app = new Koa();
const router = require("./api/index.js");
const bodyParse = require("koa-bodyparser");
const cors = require("koa2-cors");
const koaBody = require("koa-body");
const httpServer = require("http").Server(app.callback());
const static = require("koa-static");
const { accessLogger, logger } = require("./logs/index");
const { getCookies } = require("./utils/getCookies");
global.ioList = {};
getCookies();
setInterval(getCookies, 7 * 24 * 60 * 60 * 1000);
app.context.logger = logger;
app.use(accessLogger()); //中间件
app.on("error", (err, ctx) => {
  logger.error(err);
  console.log(err)
});
app.use(static(__dirname + "/upload"));
app.use(
  cors({
    origin: "*",
    maxAge: 60 * 60 * 24 * 30,
  })
);
app.use(
  koaBody({
    multipart: true,
    formidable: {
      maxFileSize: 2000 * 1024 * 1024, // 设置上传文件大小最大限制，默认2M
    },
  })
);
app.use(bodyParse());
app.use(router.routes());
app.use(router.allowedMethods());
httpServer.listen(3003, "0.0.0.0");
